package com.hgm.study.ui.components


import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Divider
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.accompanist.placeholder.PlaceholderHighlight
import com.google.accompanist.placeholder.material.placeholder
import com.google.accompanist.placeholder.material.shimmer
import com.hgm.study.model.entity.Article

/**
 * 文章列表 item
 */
@Composable
fun ArticleItem(
      article: Article,
      listLoader: Boolean,
      modifier: Modifier = Modifier
) {

      Column(
            modifier = modifier
                  .padding(top = 16.dp, start = 16.dp, end = 16.dp, bottom = 8.dp)
      ) {
            Text(
                  text = article.title,
                  fontSize = 20.sp,
                  maxLines = 2,
                  overflow = TextOverflow.Ellipsis,
                  modifier = Modifier
                        .padding(bottom = 8.dp)
                        .placeholder(
                              visible = !listLoader,
                              highlight = PlaceholderHighlight.shimmer()
                        )
            )

            Row(
                  modifier = Modifier
                        .fillMaxWidth()
                        .padding(bottom = 8.dp),
                  horizontalArrangement = Arrangement.SpaceBetween
            ) {
                  Text(
                        text = article.source,
                        color = Color(0xFF999999),
                        fontSize = 14.sp,
                        modifier = Modifier.placeholder(
                              visible = !listLoader,
                              highlight = PlaceholderHighlight.shimmer()
                        )
                  )
                  Text(
                        text = article.time,
                        color = Color(0xFF999999),
                        fontSize = 14.sp,
                        modifier = Modifier.placeholder(
                              visible = !listLoader,
                              highlight = PlaceholderHighlight.shimmer()
                        )
                  )
            }

            Divider()
      }

}

